﻿Imports MySql.Data
Imports MySql.Data.MySqlClient

Module databaseFunctions

    Public dbase_host As String
    Public dbase_uname As String
    Public dbase_pass As String
    Public dbase_db As String
    Public dbase_connected As Boolean

    Public Function runSQL(ByVal sqlStr As String) As DataTable
        Dim connStr As String = "Database=idiotBox; Data Source=127.0.0.1; User Id=root; Password=conundra; Allow Zero Datetime=true"
        Dim conn As New MySqlConnection(connStr)
        Dim myCommand As New MySqlCommand
        Dim myAdapter As New MySqlDataAdapter
        Dim sqlRes As New DataTable

        myCommand.Connection = conn
        myCommand.CommandText = sqlStr
        myAdapter.SelectCommand = myCommand
        '       Try
        myAdapter.Fill(sqlRes)
        '      Catch ex As Exception
        'MsgBox("SQL Error: " & ex.ToString)
        '     End Try
        runSQL = sqlRes
    End Function

    Public Function cleanSQL(ByVal inputText As String) As String
        Dim outText As String

        outText = Replace(inputText, "'", "\'")
        outText = Replace(outText, Chr(34), "\" & Chr(34))
        outText = Replace(outText, "’", "\’")
        outText = Replace(outText, "`", "\`")

        cleanSQL = outText
    End Function
End Module
